package com.zzyl.framework.config;

import com.aliyun.iot20180120.Client;
import com.aliyun.teaopenapi.models.Config;
import com.zzyl.framework.config.properties.AliIoTConfigProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class IotClientConfig {
    /**
     * 声明一个第三方bean对象，要代表阿里云的IotClient
     */
    @Bean
    public Client client(AliIoTConfigProperties aliIoTConfigProperties) throws Exception {
        Config config = new Config();
        config.setAccessKeyId(System.getenv("OSS_ACCESS_KEY_ID"));
        config.setAccessKeySecret(System.getenv("OSS_ACCESS_KEY_SECRET"));
        config.setRegionId(aliIoTConfigProperties.getRegionId());

        return new Client(config);
    }
}
